package HomeTest;

import java.util.ArrayList;
import java.util.List;

public class CollectionDemo6 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println("list:"+list);

        String s = list.get(3);//获取下标3位置的元素
        System.out.println("s:"+s);
        for (int i =0;i<list.size();i++ ){
            System.out.println(list.get(i));
        }


        list.set(2,"six");//将list中为2的元素设置为six-----常规操作
        //String old = list.set(2,"six");//将list中下标为2的元素设置为six，同时返回被替换的元素
        //System.out.println(old);
        System.out.println("list:"+list);
    }
}
